package com.ruoyi.web.controller.eamp;

import com.ruoyi.common.annotation.IEampReAddLog;
import com.ruoyi.common.annotation.IEampReEditLog;
import com.ruoyi.common.annotation.IEampReRemoveLog;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.eamp.domain.EampReMan;
import com.ruoyi.eamp.domain.EampSrMan;
import com.ruoyi.eamp.domain.vo.BingVO;
import com.ruoyi.eamp.domain.vo.EampReManVO;
import com.ruoyi.eamp.service.IEampReManService;
import com.ruoyi.eamp.service.IEampSrManService;
import com.ruoyi.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 参试设备表Controller
 * 
 * @author ruoyi
 * @date 2024-08-08
 */
@RestController
@RequestMapping("/eamp/re_man")
public class EampReManController extends BaseController
{
    @Autowired
    private IEampReManService eampReManService;

    @Autowired
    private IEampSrManService eampSrManService;

    @Autowired
    private ISysDeptService deptService;

    /**
     * 查询参试设备表列表
     */
    @PreAuthorize("@ss.hasPermi('eamp:re_man:list')")
    @GetMapping("/list")
    public TableDataInfo list(EampReMan eampReMan)
    {
        startPage();
        List<EampReMan> list = eampReManService.selectEampReManList(eampReMan);
        return getDataTable(list);
    }

    /**
     * 获取不分页的设备列表reList
     */
    @GetMapping("/reList")
    public TableDataInfo reList()
    {
        EampReMan eampReMan = new EampReMan();
        eampReMan.setDelFlg(1L);
        List<EampReMan> list = eampReManService.selectEampReManList(eampReMan);
        return getDataTable(list);
    }

    /** 查询库房列表srList
    * */
    @GetMapping("/srList")
    public TableDataInfo srList()
    {
        EampSrMan eampSrMan = new EampSrMan();
        eampSrMan.setDelFlg(1L);
        List<EampSrMan> list = eampSrManService.selectEampSrManList(eampSrMan);
        return getDataTable(list);
    }

    /** 查询部门列表deptList
    * */
    @GetMapping("/deptList")
    public AjaxResult deptList()
    {
        SysDept dept = new SysDept();
        List<SysDept> depts = deptService.selectDeptList(dept);
        return success(depts);
    }

    /**
     * 导出参试设备表列表
     */
    @PreAuthorize("@ss.hasPermi('eamp:re_man:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, EampReMan eampReMan)
    {
        List<EampReMan> list = eampReManService.selectEampReManList(eampReMan);
        ExcelUtil<EampReMan> util = new ExcelUtil<EampReMan>(EampReMan.class);
        util.exportExcel(response, list, "参试设备表数据");
    }

    /**
     * 获取参试设备表详细信息
     */
    @PreAuthorize("@ss.hasPermi('eamp:re_man:query')")
    @GetMapping(value = "/{reId}")
    public AjaxResult getInfo(@PathVariable("reId") Long reId)
    {
        return success(eampReManService.selectEampReManByReId(reId));
    }

    /**
     * 新增参试设备表
     */
    @PreAuthorize("@ss.hasPermi('eamp:re_man:add')")
    @PostMapping
    @IEampReAddLog
    public AjaxResult add(@RequestBody EampReMan eampReMan)
    {
        Long userId = SecurityUtils.getUserId();
        LocalDateTime dateTime = LocalDateTime.now();
        eampReMan.setReCreateBy(userId);
        eampReMan.setReCreateTime(dateTime);
        eampReMan.setReExResults(2L);
        return toAjax(eampReManService.insertEampReMan(eampReMan));
    }

    /**
     * 修改参试设备状态
     *
     */
    @PreAuthorize("@ss.hasPermi('eamp:re_man:edit')")
    @PutMapping("/updateStatus/{id}")
    public AjaxResult updateStatus(@PathVariable("id") Long id){
        return success(eampReManService.updateEampReManById(id));
    }

    /**
    * 进行出库处理updateStock
    * */
    @PreAuthorize("@ss.hasPermi('eamp:re_man:edit')")
    @PutMapping("/updateStock/{id}")
    public AjaxResult updateStockOut(@PathVariable("id") Long id){
        return success(eampReManService.updateStockeOutEampReManById(id));
    }

    /**
     * 修改参试设备的实验结果
     *
     */
    @PreAuthorize("@ss.hasPermi('eamp:re_man:edit')")
    @PutMapping("/updateResult/{id}")
    public AjaxResult updateResult(@PathVariable Long id, @RequestBody EampReMan eampReMan){
        Long reExResults = eampReMan.getReExResults();
        return success(eampReManService.updateResult(id,reExResults));
    }

    /**
     * 修改参试设备表EampReManVO
     */
    @PreAuthorize("@ss.hasPermi('eamp:re_man:edit')")
    @PutMapping
    @IEampReAddLog
    @IEampReEditLog //负责改变库房的当前规格
    public AjaxResult edit(@RequestBody EampReManVO eampReManVO)
    {
        EampReMan eampReMan = eampReManVO.getEampReMan();
        return toAjax(eampReManService.updateEampReMan(eampReMan));
    }

    /**
     * 删除参试设备表
     *
     */
    @PreAuthorize("@ss.hasPermi('eamp:re_man:remove')")
	@DeleteMapping("/{reIds}")
    @IEampReRemoveLog
    public AjaxResult remove(@PathVariable Long[] reIds)
    {
        return toAjax(eampReManService.deleteEampReManByReIds(reIds));
    }


    /**
     * 查询库房和所对应的参试设备列表
     */
    @GetMapping("/echartList")
    public  TableDataInfo echartList()
    {
        List<List<BingVO>> stringListHashMap = eampReManService.selectEampReManEcharList();
        return getDataTable(stringListHashMap);
    }

    @GetMapping("/selectSrName")
    public  TableDataInfo selectSrName()
    {
        List<String> strings = eampReManService.selectSrName();
        return getDataTable(strings);
    }
    @GetMapping("/getMax")
    public  AjaxResult getMax()
    {
        int strings = eampReManService.getMax();
        return AjaxResult.success(strings);
    }
}
